package com.day2;

import javax.servlet.ServletException;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class Show extends HttpServlet{
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //super.service(req, resp);
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

        Cookie[] cks=req.getCookies();
        if (cks!=null){
            for (Cookie cook:cks){
                if ("name".equals(cook.getName())){
                    req.setAttribute("name",cook.getValue());
                    req.getRequestDispatcher("success").forward(req,resp);
                }
            }
        }
        Object name = req.getAttribute("name");
        System.out.println("name="+name);
        resp.getWriter().print("<form action=\"/hhh/Login\" method=\"post\">" +
                "        用户名: <input type=\"text\" name=\"username\"/> <span style='color:red'>"
                +"</span><br />" +
                "        密码：<input type=\"password\" name=\"password\"/><br /><input type=\"submit\"/>" +
                "    </form>");


    }
}
